package com.wzg.pldroidplayer.recyclerviewdemo;

import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class VideoPlayerReady extends AppCompatActivity{
    private Button VideoUriPaste;
    private Button VideoUriPlayer;
    private EditText VideoUri;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_player_ready);

        VideoUriPaste = findViewById(R.id.VideoUriPaste);
        VideoUriPaste.setOnClickListener(new ButtonClick());
        VideoUriPlayer = findViewById(R.id.VideoUriPlayer);
        VideoUriPlayer.setOnClickListener(new ButtonClick());
        VideoUri = findViewById(R.id.VideoUri);

        VideoUri.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                if (VideoUri.getText().length()==0){
                    VideoUriPaste.setText("一键粘贴");
                }else {
                    VideoUriPaste.setText("一键清空");
                }
            }
        });

    }

    public void UriPaste(){
            if (VideoUriPaste.getText().equals("一键粘贴")){
                ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                String VideoUriString = clipboard.getText().toString();
                VideoUri.setText(VideoUriString);
                Toast.makeText(this, "粘贴成功", Toast.LENGTH_SHORT).show();
            }else {
                VideoUri.setText("");
            }
    }

    public void CarryUriJump(){
        if (VideoUri.getText().length()==0){
            Toast.makeText(this, "请输入视屏地址", Toast.LENGTH_SHORT).show();
        }else {
            Intent intent = new Intent(VideoPlayerReady.this,VideoPlayerPalyer.class);
            Bundle bundle = new Bundle();
            bundle.putString("VideoUri",VideoUri.getText().toString());
            intent.putExtras(bundle);
            startActivity(intent);
        }
    }


    class ButtonClick implements View.OnClickListener{
        @Override
        public void onClick(View view) {
            switch (view.getId()){
                case R.id.VideoUriPaste:
                    UriPaste();
                    break;
                case R.id.VideoUriPlayer:
                    CarryUriJump();
                    break;
            }
        }
    }
}
